home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C++
/
Applications
/
nanoInstall 1.0
/
source
/
writeThem.cp
< prev
Wrap
Text File
|
1996-07-05
|
3KB
|
117 lines
#include "nanoInstall.h"
OSErr writeOne( FSSpec &theFSSpec, short resNo);
OSErr PutForkAndClose( short theFork, OSType theType, short resNo);
OSErr writeThem()
{
OSErr result = -1; // user canceled
Handle promptResource = Get1Resource( 'STR ', 128);
standardputfile sf( (unsigned char *)*promptResource);
const short numFilesToInstall = Count1Resources( 'fNam');
if( numFilesToInstall == 1)
{
Handle nameResource = Get1Resource( 'fNam', 128);
if( sf.doIt( (unsigned char *)*nameResource))
{
result = writeOne( sf.sfFile, 128);
}
ReleaseResource( nameResource);
} else {
Handle folderNameResource = Get1Resource( 'STR ', 129);
if( sf.doIt( (unsigned char *)*folderNameResource))
{
FSSpec theNewFSSpec;
long createdDirID = 0;
result = FSpDirCreate( &sf.sfFile, smCurrentScript, &createdDirID);
if( result == noErr)
{
theNewFSSpec.vRefNum = sf.sfFile.vRefNum;
theNewFSSpec.parID = createdDirID;
short resNo = 128;
Handle nameResource = Get1Resource( 'fNam', resNo);
while( nameResource != 0)
{
BlockMoveData( *nameResource, theNewFSSpec.name, GetHandleSize( nameResource));
writeOne( theNewFSSpec, resNo);
resNo += 1;
ReleaseResource( nameResource);
nameResource = Get1Resource( 'fNam', resNo);
}
}
}
ReleaseResource( folderNameResource);
}
ReleaseResource( promptResource);
return result;
}
OSErr writeOne( FSSpec &theFSSpec, short resNo)
{
OSErr result = noErr;
(void)FSpDelete( &theFSSpec);
FSpCreateResFile( &theFSSpec, '????', '????', smCurrentScript);
if( (result = ResError()) == noErr)
{
short resFork = 0;
if( (result = FSpOpenRF( &theFSSpec, fsWrPerm, &resFork)) == noErr)
{
result = PutForkAndClose( resFork, 'RsFk', resNo);
}
short dataFork = 0;
if( (result = FSpOpenDF( &theFSSpec, fsWrPerm, &dataFork)) == noErr)
{
result = PutForkAndClose( dataFork, 'DtFk', resNo);
}
//
// set finder info, except for the file location
//
FInfo fndrInfo;
(void)FSpGetFInfo( &theFSSpec, &fndrInfo);
Handle theResource = Get1Resource( 'fInf', resNo);
FInfo *origInfo = (FInfo *)*theResource;
fndrInfo.fdType = origInfo->fdType;
fndrInfo.fdCreator = origInfo->fdCreator;
fndrInfo.fdFlags = origInfo->fdFlags & (~kHasBeenInited);
ReleaseResource( theResource);
(void)FSpSetFInfo( &theFSSpec, &fndrInfo);
}
return result;
}
OSErr PutForkAndClose( short theFork, OSType theType, short resNo)
{
Handle theResource = Get1Resource( theType, resNo);
long numtowrite = GetHandleSize( theResource);
OSErr result = FSWrite( theFork, &numtowrite, *theResource);
FSClose( theFork);
ReleaseResource( theResource);
return result;
}